package com.tech.algorithm.sort;

import java.util.Arrays;

/**
 * @Description:选择排序
 * @Author: zl
 * @Date: 2019/9/20 15:40
 */
public class SelectSort {

    public static void main(String[] args) {
        int arr[] = {1, 2, 3, -1, -8};
        for (int i = 0; i < arr.length - 1; i++) {
            int min = arr[i];
            int minIndex = i;
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[j] < min) {
                    min = arr[j];
                    minIndex = j;
                }
            }

            if (minIndex != i) {
                arr[minIndex] = arr[i];
                arr[i] = min;
            }

        }
        System.out.println(Arrays.toString(arr));
    }
}
